﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace EventLogManager
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnConfirm_Click(object sender, EventArgs e)
        {
            lblSourceExists.Text = EventLog.SourceExists(txtEventSource.Text).ToString();

            lblLogNameFromSourceName.Text = EventLog.LogNameFromSourceName(txtEventSource.Text, ".");
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                EventLog.DeleteEventSource(txtEventSource.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            MessageBox.Show("EventSource '" + txtEventSource.Text + "' Deleted.");
        }

        private void btnCreate_Click(object sender, EventArgs e)
        {
            txtLogName.Text = txtLogName.Text.Trim();

            if (String.IsNullOrEmpty(txtLogName.Text))
            {
                MessageBox.Show("LogName can't be null.");
                return;
            }

            try
            {
                EventLog.CreateEventSource(txtEventSource.Text, txtLogName.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

        }

        private void btnDeleteLog_Click(object sender, EventArgs e)
        {
            txtLogName.Text = txtLogName.Text.Trim();

            try
            {
                EventLog.Delete(txtLogName.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            MessageBox.Show("The '" + txtLogName.Text + "' LogName deleted.");
        }
    }
}
